<?php namespace App\Exceptions;

use Exception;

class WechatException extends Exception
{
    const CodeIsNull = 0x01;
    const RequestIsFail = 0x02;
    const WeChatSignInFail = 0x03;
    const GetAccessTokenFail = 0x04;
    const GetOpenIdFail = 0x05;
    const TicketIsNull = 0x06;
    const ThatPayPriceIsWrong = 0x07;

    public function __construct($code, array $data = [], Exception $previous = null)
    {
        switch ($code) {
            case self::CodeIsNull:
                $message = trans('code为空');
                break;
            case self::RequestIsFail:
                $message = trans('请求失败');
                break;
            case self::WeChatSignInFail:
                $message = trans('授权访问错误');
                break;
            case self::GetAccessTokenFail:
                $message = trans('获取access_token失败');
                break;
            case self::GetOpenIdFail:
                $message = trans('获取open_id失败');
                break;
            case self::TicketIsNull:
                $message = trans('ticket未获取成功，请刷新后重试');
                break;
            case self::ThatPayPriceIsWrong:
                $message = trans('支付金额错误');
                break;
            default:
                $message = trans('未知错误');
                break;
        }

        parent::__construct($message, $code, $previous);
    }

}